﻿
namespace SkyWalking.ProductService.Registrys;

/// <summary>
/// Host服务
/// </summary>
public class ServiceRegistryHostService : IHostedService
{
    public ConsulServiceRegistry consulServiceRegistry { get; set; }
    public ServiceRegistryHostService(ConsulServiceRegistry consulServiceRegistry)
    {
        this.consulServiceRegistry = consulServiceRegistry;
    }

    /// <summary>
    /// 项目启动时，调用服务注册方法
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public Task StartAsync(CancellationToken cancellationToken)
    {
        consulServiceRegistry.Registry();
        return Task.CompletedTask;  
    }

    /// <summary>
    /// 项目关闭时，调用服务删除方法
    /// </summary>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task StopAsync(CancellationToken cancellationToken)
    { 
        consulServiceRegistry.DeRegistry();
        return Task.CompletedTask;  
    }
}
